package cn.hotel.service;

import cn.hotel.dao.ClientInformationManagements;
import cn.hotel.dao.ClientInformationManagementsDao;
import cn.hotel.pojo.ClientInformationManagement;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ClientInformationManagementServiceImpl implements ClientInformationManagementService{

    ClientInformationManagements clientInformationManagements = new ClientInformationManagementsDao();
    @Override
    public Map<String, Object> cim(String mobilePhone, int current, int numData) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = (current - 1) * numData;
            List<ClientInformationManagement> clientInformationManagementList = clientInformationManagements.cim(mobilePhone,num,numData);
            if(clientInformationManagementList != null && clientInformationManagementList.size() > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",clientInformationManagementList);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> amend(ClientInformationManagement clientInformationManagement) {
        return null;
    }

    @Override
    public Map<String, Object> deletes(String identityCard) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = clientInformationManagements.deletes(identityCard);
            if(num > 1){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> sum(String mobilePhone) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = clientInformationManagements.sum(mobilePhone);
            if(num > 1){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }
}
